<?php
namespace App\Http\Controllers\WebApi\Home;

use App\Utilities\SlideCode;
use Illuminate\Http\Request;

class SlideCodeController extends BaseController
{
    /**
     * 滑块验证码
     */

    protected $sc;
    protected $db;

    public function __construct()
    {
        parent::__construct();
        $this->sc = new SlideCode();
    }

    /**
     * 获取验证码信息
     */
    public function getSlide(Request $request)
    {
        $stamp = time().rand(1000,9999);
        $resCode = $this->sc->setMake($stamp);
        $resCode['stamp'] = $stamp;
        return $resCode;
    }

    /**
     * 验证
     */
    public function setCheck(Request $request)
    {
        $stamp = $request->post('stamp','');
        $width = $request->post('width','');
        if (!$stamp) { return $this->toJson(-2); }
        return $this->sc->setCheck($stamp,$width);
    }
}